package com.frank.towerrush.adapter;

import java.util.List;

import com.frank.towerrush.R;
import com.frank.towerrush.split.Tower;
import com.frank.towerrush.util.SystemParameter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HelpAdapter extends BaseAdapter {
    List<Tower> towerList;
    LayoutInflater inflater;

    public HelpAdapter(Context context) {
        inflater = LayoutInflater.from(context);
        towerList = SystemParameter.towers;
    }

    @Override
    public int getCount() {
        return towerList.size();
    }

    @Override
    public Tower getItem(int position) {
        return towerList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        class Views {
            TextView name;
            ImageView image;
            TextView info;

            public Views(View v) {
                name = (TextView) v.findViewById(R.id.help_item_name);
                image = (ImageView) v.findViewById(R.id.help_item_image);
                info = (TextView) v.findViewById(R.id.help_item_info);
            }
        }
        Views views = null;
        if (view == null) {
            view = inflater.inflate(R.layout.help_item, null);
            views = new Views(view);
            view.setTag(views);
        } else {
            views = (Views) view.getTag();
        }
        Tower t = getItem(position);
        views.name.setText(t.getName());
        views.image.setImageBitmap(t.getImage());
        views.info.setText(t.getInfo());
        return view;
    }

}
